<template>
	<!-- 
	swiper中的transfrom会使fixed失效,此时用height固定高度; 
	swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
	-->
	<!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
	<!-- top的高度等于悬浮菜单tabs的高度 -->
	<MescrollUni  :ref="'mescrollRef'+i"  @init="mescrollInit" :height="height" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
		<!-- 数据列表 -->
		<view class="plr28">
			<!-- <list :list="goods" @getWithdrawList='doSearch' :name='name'></list> -->
			<view   :id="'good'+item.id"  v-for="(item,index) in goods" :key="index" class="withdraw-item  flex-between" :class="{'widthdraw-active1':item.type===1,'widthdraw-active3':item.type === 3,'widthdraw-active2':item.type===2}"  v-if="goods.length >0">
				<view class="flex alcenter">
					<image src="/static/withdraw/awal2@2x.png" v-if="item.type === 1" class="withdraw-item-img" mode="aspectFill"></image>
					<image :src="item.avatarUrl" v-if="item.type === 3" class="withdraw-item-img"></image>
					<image src="/static/withdraw/bank.png" v-if="item.type != 1 && item.type !=3" class="withdraw-item-img"></image>
					<view class=" ml16 ft28" >
						<view class="c_737373">{{item.type===1?item.name:item.type === 3?'微信昵称':item.bank_name}}{{item.account_type === 1?'(对公账号)':""}}</view>
						<view class="mt16 c_9C8446">{{item.type === 1?item.account:item.type === 3?item.nickName:item.account}}</view>
					</view>
				</view>
				<view class="flex alcenter">
					<image src="@/static/user/setting/update_btn.png"  @click="update(item)" v-if="item.type != 3" class="main_img"></image>
					<image src="@/static/user/setting/del_btn.png" @click="del(item)" class="main_img"></image>
				</view>
			</view>
			<view  class=" add-withdrwadf flex-center c_999" @click="addWithdraw()">
				<view class="icon-jiahao iconfont ft50"></view>
				<view class="ft32 ml10">{{tabs[i].name ==="支付宝"?'添加支付宝':tabs[i].name ==="微信"?"添加微信":"添加银行卡"}}</view>
			</view>
		</view>
		<withdrawItem ref="withdraw_main" @getWithdrawList='doSearch' :name='name' @judge_img='judge_img'></withdrawItem>
	</MescrollUni>
</template>

<script>

	
	import MescrollMixin from "@/components/lccg/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/lccg/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	import MescrollUni from '@/components/lccg/mescroll-uni/components/mescroll-uni/mescroll-uni.vue'
	import * as userApi from '@/api/user'
	import withdrawItem from '@/components/withdrawItem/index.vue'
	export default {
		mixins: [MescrollMixin,MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption:{
					auto:false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption:{
					auto:false, // 不自动加载
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 空空如也 ~', // 提示
						btnText: '去看看'
					}
				},
				goods: [] ,//列表数据
				options: [{
					value: 1,
					label: '支付宝'
				}, {
					value: 3,
					label: '微信'
				}, {
					value: 2,
					label: '银行卡'
				}],
				img:"",
				name:"请先实名认证"
			}
		},
		props:{
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default(){
					return 0
				}
			},
			tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
				type: Array,
				default(){
					return []
				}
			},
			height: [Number,String] // mescroll的高度
		},
		components:{
			MescrollUni,
			withdrawItem
		},
		methods: {
			// 修改账号
			update(item){
				if(item.type === 1){
					this.$refs.withdraw_main.openUpdataAlipay(item.id,item.account)
				}else if(item.type === 2){
					this.$refs.withdraw_main.openUpdateBank(item.id,item.account,item.bank_name)
				}
			},
			del(item){
				this.$refs.withdraw_main.openDeal(item.id,item.type)
			},
			bankName(name){
				this.$refs.withdraw_main.bankSelect(name)
			},
			// 添加账号
			addWithdraw(){
				if(this.tabs[this.i].name === "支付宝"){
					this.$refs.withdraw_main.openAddAlipay()
				}else if(this.tabs[this.i].name === "微信"){
					this.$refs.withdraw_main.openAddWx()
				}else{
					this.$refs.withdraw_main.openAddBank()
				}
			},
			goDetil_xcx(){
				
			},
			upCallback(){
				this.$emit("getWithdrawList")
			},
			// 实名信息
			loadDetail1() {
				let token = uni.getStorageSync("AccessToken")
				userApi.getUserRealStatus({
					wxapp_id: this.$wxapp_id,
					token: token,
					type:1
				})
				.then(result => {
					if(result.code === 1){
						this.name = result.data.name
						
					}else{
						this.$fault("您还未实名认证")
					}
					
				})
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				let _this = this;
				let token = uni.getStorageSync("AccessToken")
				this.loadDetail1()
				let keyword = this.tabs[this.i].name
				let keytype = 1
				for(let i=0;i<this.options.length;i++){
					if(keyword === this.options[i].label){
						keytype = this.options[i].value
					}
				}
				if(this.tabs[this.i].name === '微信'){
					if(!this.img){
						setTimeout(() => {
							this.$refs.withdraw_main.getQrcode()
						},500)
						
					}
				}
				userApi.getWithdrawList({
					wxapp_id: this.$wxapp_id,
					token: token,
					type:keytype
				}).then(res=> {
					this.mescroll.endSuccess(res.data.length+1);
					//设置列表数据
					if(page.num == 1) this.goods = []; //如果是第一页需手动制空列表
					this.goods=this.goods.concat(res.data); //追加新数据
				})
			},

			doSearch(){
				this.goods = []; // 先清空列表,显示加载进度
				this.mescroll.resetUpScroll();
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			judge_img(img){
				this.img = img
			},
		}
	}
</script>
<style lang="scss">
	.withdraw-item{
		transition: 0.2s linear;
		margin-bottom: 24rpx;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		minheight: 172rpx;
		background: #FCFDFD;
		box-shadow: 0rpx 8rpx 40rpx 0rpx #E8EBEE;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		border: 4rpx solid #FFFFFF;
	}
	.withdraw-item:first-child{
		margin-top: 40rpx;
	}
	.withdraw-item + .withdraw-item{
		margin-top: 20rpx;
	}
	.widthdraw-active1{
		// background-image: url('@/static/user/setting/zhifu_bg.png');
	}
	.widthdraw-active2{
		// background-image: url('@/static/user/setting/bnak_bg.png');
	}
	.widthdraw-active3{
		// background-image: url('@/static/user/setting/wechat_bg.png');
	}

	.withdraw-item-img{
		height: 100rpx;
		width: 100rpx;
		border-radius: 100%;
		background-color: #FFFFFF;
		border: 10rpx solid #FFFFFF;
	}
	.main_img{
		height: 40rpx;
		width: 40rpx;
	}
	.main_img + .main_img{
		margin-left: 20rpx;
	}
	.hand-btn{
		position: absolute;
		right: 20rpx;
		top: 50rpx;
	}
	.add-withdrwadf{
		transition: 0.2s linear;
		margin-bottom: 24rpx;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		minheight: 172rpx;
		background: #FCFDFD;
		box-shadow: 0rpx 8rpx 40rpx 0rpx #E8EBEE;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		border: 4rpx solid #FFFFFF;
	}
</style>
